package StudyCode.Exception;

import java.util.Scanner;

/**
 * @author lixiaoyao
 * @date 2018/10/29 0029、下午 4:56
 * @description StackTrace测试代码
 */
public class StackTraceTest {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.print("Enter n:");
		int n = in.nextInt();
		factorial(n);
	}

	private static int factorial(int n) {
		System.out.println("factorial(" + n + "):");
		Throwable throwable = new Throwable();
		StackTraceElement[] stackTraceElements = throwable.getStackTrace();
		for (StackTraceElement stackTraceElement : stackTraceElements) {
			System.out.println(stackTraceElement);
		}
		int r;
		if (n <= 1) {
			r = 1;
		} else {
			r = n * factorial(n - 1);
		}
		System.out.println("return" + r);
		return r;
	}

}
